#ifndef __XSIP_TRANSACTION_H__
#define __XSIP_TRANSACTION_H__
#include "xevent.h"

class XSIPCall;
class XSIPRequest;
class XSIPResponse;
class XSIPTransport;
class XSIPTransactionState;
class XSIP_API XSIPTransaction : public XSIPEvent {
public:
	enum {
		TRANSACTION_TYPE_CMD = 1,
		TRANSACTION_TYPE_DIALOG_OPEN,
		TRANSACTION_TYPE_DIALOG_UPDATE,
		TRANSACTION_TYPE_DIALOG_CLOSE,
	};

	enum {
		TSX_STATE_DESTORY = 0xdead,
	};
	XSIPTransaction(int type);
	virtual ~XSIPTransaction();
	int getTransactionType();
	virtual void* getObject(const char* name) const;

	void setTransactionId(char* id);
	char* getTransactionId();

	XSIPRequest* getRequest();
	XSIPResponse* getResponse();
	void setRequest(XSIPRequest* request);
	void setResponse(XSIPResponse* response);

	XSIPRequest* getAck();
	void setAck(XSIPRequest* request);

	XSIPCall* getOwner();
	void setOwner(XSIPCall* owner);

	virtual void onEvent(XSIPTransaction* transaction, int eventCode) = 0;

	XSIPTransport* getTransport();
	void setTransport(XSIPTransport* transport);

	XSIPTransactionState* getTranactionState();
	void setTransactionState(XSIPTransactionState* state);

	int getState();
	void setState(int state);

	friend class XSIPEngine;
protected:
	int m_transactionType;
	XSIPCall* m_owner;
	XSIPTransport* m_transport;
	XSIPRequest *m_request;
	XSIPResponse *m_response;
	XSIPTransactionState *m_state;
	char m_id[64];
	XSIPRequest* m_ack;
	int m_tsxState;
};

#endif 